package com.bos.controller;

import com.bos.dao.KabupatenDAO;
import com.bos.domain.Kabupaten;
import com.bos.editor.KabupatenEditor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * User: Deny Prasetyo, S.T.
 * http://www.jasoet.com
 */
@Controller
public class NewsController {

    private KabupatenDAO kabupatenDAO;

    @Autowired
    public void setKabupatenDAO(KabupatenDAO kabupatenDAO) {
        this.kabupatenDAO = kabupatenDAO;
    }

    @RequestMapping(value = "/news/{id}", method = RequestMethod.GET)
    public String home(ModelMap modelMap, @PathVariable("id") Integer id) {
        modelMap.addAttribute("name", "Propinsi");
        modelMap.addAttribute("kabMenuList", kabupatenDAO.getAll());
        return "/news/"+id;
    }

    @InitBinder
    protected void initBinder(WebDataBinder binder) throws Exception {
        binder.registerCustomEditor(Kabupaten.class, new KabupatenEditor(kabupatenDAO));
    }
}
